package com.cj.pj.sys.service.impl;

import com.cj.pj.sys.common.annotation.AddLogs;
import com.cj.pj.sys.common.exception.ServiceException;
import com.cj.pj.sys.common.pojo.PageObject;
import com.cj.pj.sys.dao.SysLogDao;
import com.cj.pj.sys.pojo.SysLog;
import com.cj.pj.sys.service.SysLogService;
import com.cj.pj.sys.util.CheckedUtil;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysLogServiceImpl implements SysLogService {
    @Autowired
    SysLogDao sysLogDao;


    @Override
    @AddLogs("查找日志")
    public PageObject<SysLog> findPageObject(Integer currentPage, String username) {
        CheckedUtil.checkResult(currentPage==null||currentPage<1,"页码出错");
        int rowCount=sysLogDao.getRowCount(username);
        CheckedUtil.checkResult(rowCount==0,"没有查到对应记录");
        int pageSize=5;
        int lastpageSize=currentPage*pageSize>rowCount?rowCount%pageSize:pageSize;
        return new PageObject<SysLog>(currentPage,sysLogDao.getPageObject(username,(currentPage-1)*pageSize,lastpageSize),rowCount);
    }

    @Override
    @AddLogs("删除日志")
    public String deleteById(Integer... ids) {
        CheckedUtil.checkResult(ids==null||ids.length==0,"选择的数据id错误");
        Integer row=sysLogDao.deleteById(ids);
        CheckedUtil.checkResult(row==0,"删除出错，所选数据可能已删除");
        return "成功删除"+row+"条数据";
    }

    @Override
    public void insert(SysLog sysLog) {
        sysLogDao.insert(sysLog);
    }
}
